package com.leanit.pmc.common.bean;


import com.leanit.pmc.common.util.LeanItStringUtil;
import org.apache.commons.lang3.StringUtils;

/**
 * grid请求bean
 */
public class GridRequest {

    int rows = 1;
    int page;
    int start;
    int end;
    long total;
    String sidx;
    String sord;

    public int getRows() {
        return this.rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getPage() {
        return this.page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getEnd() {
        return (page * rows - 1) > 0 ? (page * rows) : 1;
    }

    public int getStart() {
        return (page - 1) * rows + 1;
    }

    public long getTotal() {
        return this.total;
    }

    public void setTotal(final long total) {
        this.total = total;
    }

    public String getSidx() {
        return this.sidx;
    }

    public void setSidx(String sidx) {
        this.sidx = sidx;
    }

    public String getSord() {
        return this.sord;
    }

    public void setSord(String sord) {
        this.sord = sord;
    }

    public String getSortOrder() {
        if (StringUtils.isEmpty(getSidx())) {
            return "";
        }
        return LeanItStringUtil.transLateUpper2UnderLine(getSidx()) + " " + getSord();
    }

    @Override
    public String toString() {
        return "GridRequest{" +
                "rows=" + rows +
                ", page=" + page +
                ", start=" + getStart() +
                ", end=" + getEnd() +
                ", total=" + total +
                ", sidx='" + sidx + '\'' +
                ", sord='" + sord + '\'' +
                '}';
    }
}
